/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaUploadFile from "@/components/ma-upload-file/index.vue";
import { concat } from "lodash-es";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { page as merchantPage } from "$/attractions/commerce/api/commerceMerchant.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "商户名称",
      prop: "merchant_id",
      render: () => MaRemoteSelect,
      renderProps: {
        api: merchantPage,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.merchant_name || `商户名称${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择商户名称",
        clearable: true,
        multiple: false,
      },
    },
    {
      label: "资质名称",
      prop: "qualification_name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "资质名称" }) },
    },
    {
      label: "资质类型",
      prop: "qualification_type",
      render: () => MaDictSelect,
      renderProps: {
        data: [
          { label: "食品经营许可证", value: 1 },
          { label: "卫生许可证", value: 2 },
          { label: "消防许可证", value: 3 },
          { label: "其他证书", value: 4 },
        ],
        placeholder: t("form.pleaseInput", { msg: "资质类型" }),
        clearable: true,
        multiple: false,
      },
      itemProps: {
        rules: [{ required: true, message: "请选择资质类型" }],
      },
    },
    {
      label: "资质证书号",
      prop: "qualification_id",
      render: "input",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "资质证书号" }),
      },
    },
    {
      label: "发证机关",
      prop: "issuing_authority",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "发证机关" }) },
    },
    {
      label: "发证日期",
      prop: "issue_date",
      render: "DatePicker",
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "发证日期" }),
        type: "date",
        format: "YYYY-MM-DD",
        valueFormat: "YYYY-MM-DD",
      },
      mode: "date",
      showTime: false,
    },
    {
      label: "资质文件",
      prop: "qualification_file",
      render: () => MaUploadFile,
      renderProps: {
        placeholder: t("form.pleaseInput", { msg: "资质文件" }),
      },
      multiple: false,
    },
  ]);
}
